package cn.iocoder.yudao.module.eval.dal.mysql.major;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.eval.dal.dataobject.major.MajorDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.eval.controller.admin.major.vo.*;

/**
 * 专业管理 Mapper
 *
 * @author 龙头企业
 */
@Mapper
public interface MajorMapper extends BaseMapperX<MajorDO> {

    default PageResult<MajorDO> selectPage(MajorPageReqVO reqVO) {
        // 使用自定义条件查询，避免直接使用方法引用
        LambdaQueryWrapperX<MajorDO> queryWrapper = new LambdaQueryWrapperX<>();
        queryWrapper.eqIfPresent(MajorDO::getCode, reqVO.getCode());
        queryWrapper.likeIfPresent(MajorDO::getName, reqVO.getName());
        queryWrapper.eqIfPresent(MajorDO::getLevel, reqVO.getLevel());
        // 使用SFunction类型的Lambda表达式替代方法引用
        queryWrapper.apply(reqVO.getUpperLevelCode() != null, 
            "upper_level_code = {0}", reqVO.getUpperLevelCode());
        queryWrapper.apply(reqVO.getNextLevelCode() != null,
            "next_level_code = {0}", reqVO.getNextLevelCode());
        queryWrapper.apply(reqVO.getQualificationSkillLevel() != null,
            "qualification_skill_level = {0}", reqVO.getQualificationSkillLevel());
        queryWrapper.apply(reqVO.getMajorCategoryId() != null,
            "major_category_id = {0}", reqVO.getMajorCategoryId());
        queryWrapper.eqIfPresent(MajorDO::getStatus, reqVO.getStatus());
        queryWrapper.betweenIfPresent(MajorDO::getCreateTime, reqVO.getCreateTime());
        queryWrapper.orderByDesc(MajorDO::getId);
        
        return selectPage(reqVO, queryWrapper);
    }

    default MajorDO selectByCode(String code) {
        return selectOne(MajorDO::getCode, code);
    }

}